<?php


namespace App\Http\Controllers\Saas;


use App\Http\Controllers\Controller;
use App\Http\Resources\PaginationCollection;
use App\Model\Agent;
use App\Model\AgentHasShop;
use App\Model\TestRecord;
use App\Utils\Result;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class TestRecordController extends Controller
{
    public function index(Request $request)
    {
        $query = TestRecord::query();
        $page = $request->input('page', 1);
        $pageSize = $request->input('pageSize', 10);
        $mac = $request->input('mac');
        $sn = $request->input('sn');
        $mobile = $request->input('mobile');

        $query->when($mac, function($q) use ($mac) {
            $q->where('mac', 'like', "%{$mac}%");
        });
        $query->when($mobile, function($q) use ($mobile) {
            $q->where('mobile', $mobile);
        });
        $query->when($sn, function($q) use ($sn) {
            $q->where('sn', $sn);
        });
        $data = $query->latest()->paginate($pageSize, ['*'], 'page', $page);
        return Result::success(new PaginationCollection($data));
    }



    public function del(Request $request)
    {
        $id = $request->input('id');
        TestRecord::where('id', $id)->delete();
        return Result::success();
    }

}
